package src

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"html/template"
	"net/http"
	"time"
)

func FuncTpl(ctx *gin.Context) {
	//fmt.Println("Jackson")
	//fmt.Print("alex")
	//fmt.Printf("\n name:%s, age:%d \n ", "wusir", 541)
	//name := fmt.Sprint("Jackson")
	//fmt.Println(name)
	//user := fmt.Sprintf("name:%s, age:%d, addr:%s", "sylar", 43, "ShangHai")
	//fmt.Println(user)

	name := "jony"
	age := 15
	addr := "北京市"

	slice_data := []string{"张三", "李四", "王五", "赵六", "孙七"}

	map_test := map[string]interface{}{
		"name": "alen",
		"age":  76,
	}
	now_time := time.Now() //.Format("2006-01-01 13:43:42")
	fmt.Println(now_time)

	map_data := map[string]interface{}{
		"name":       name,
		"age":        age,
		"addr":       addr,
		"slice_data": slice_data,
		"map_test":   map_test,
		"now_time":   now_time,
	}

	ctx.HTML(http.StatusOK, "chapter/index.html", map_data)
}

func AddNum(a, b int) int {
	return a + b
}

// qqqqqqqqq ->  qqqqqq...

func StrSlice(str string, num int) string {
	str_length := len(str)
	// 如果字符串长度小于指定长度，则直接返回字符串
	if str_length <= num {
		return str
	} else { // 否则进行逻辑加工
		new_str := str[0:num]
		return new_str + "..."
	}
}

func Template_str(str string) template.HTML {

	return template.HTML(str)
}

func SelfDefine(ctx *gin.Context) {

	ctx.HTML(http.StatusOK, "chapter/home.html", nil)
}
